package com.agricultural.state;

import com.agricultural.equipment.AgriculturalEquipment;

// 紧急停止状态
public class EmergencyStopState implements EquipmentState {
    private AgriculturalEquipment equipment;

    public EmergencyStopState(AgriculturalEquipment equipment) {
        this.equipment = equipment;
    }

    @Override
    public void start(AgriculturalEquipment equipment) {
        System.out.println(equipment.getEquipmentId() + " 处于紧急停止状态，需要先解除紧急情况");
    }

    @Override
    public void stop(AgriculturalEquipment equipment) {
        System.out.println(equipment.getEquipmentId() + " 已经处于紧急停止状态");
    }

    @Override
    public void performTask(AgriculturalEquipment equipment) {
        System.out.println(equipment.getEquipmentId() + " 处于紧急停止状态，无法执行任务");
    }

    @Override
    public void handleEmergency(AgriculturalEquipment equipment, String emergencyType) {
        System.out.println(equipment.getEquipmentId() + " (紧急停止状态) 收到紧急情况: " + emergencyType);

        if ("resolved".equalsIgnoreCase(emergencyType)) {
            System.out.println(equipment.getEquipmentId() + " 紧急情况已解除，准备就绪");
            equipment.setState(new IdleState(equipment));
        }
    }

    @Override
    public String getStateName() {
        return "紧急停止";
    }
}